package cn.itcast.controller;


import cn.itcast.domin.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//常用注解
@Controller
@RequestMapping("/anno")
@SessionAttributes(value = {"msg"})//把msg=   存入到session域中
public class AnnoController {

    @RequestMapping("/testRequestParam")
    public String testRequestParam(String username){
        System.out.println("执行了");
        System.out.println(username);
        return "success";
    }
    @RequestMapping("/testRequestBody")
    public String testRequestBody(@RequestBody String body){
        System.out.println("zhixingle....");
        System.out.println(body);
        return "success";
    }

    /**
     * PathVarable注解
     * @param id
     * @return
     */
    @RequestMapping("/testPathVariable/{sid}")
    public String testPathVariable(@PathVariable(name = "sid") String id){
        System.out.println("执行了.....");
        System.out.println(id);
        return "success";
    }
    /**
     * 获取请求头的值
     */
    @RequestMapping("/testRequestHeader")
    public String testRequestHeader(@RequestHeader(value = "Accept") String header, HttpServletRequest request, HttpServletResponse response){
        System.out.println("执行了...");
        System.out.println(header);
        return "redirect:/param.jsp";
    }
    @RequestMapping("/testCookieValue")
    public String testCookieValue(@CookieValue(value = "JSESSIONID") String cookieCValue){
        System.out.println("执行");
        System.out.println(cookieCValue);
        return "success";
    }

    /**
     * ModelAttribute注解
     * @param user
     * @return
     */
    @RequestMapping("/testModelAttribute")
    public String testModelAttribute(@ModelAttribute ("aaa") User user){
        System.out.println("执行l");
        System.out.println(user);
        return "success";
    }

}
